// mine//pages/mine_collect/index.js
const apis=require('../../../utils/api').apis;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataArr:[],
    total:0,
    userType:null,
    pageNo:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   let userType=wx.getStorageSync('userInfo')?wx.getStorageSync('userInfo').userType:'user';
   this.setData({
     userType
   })
      // this.getData()
  },
  getData(){
    wx.showLoading({
      title: '加载中',
    })
    apis.curriculumQueryUserCollectCurriculum({
      pageNo:this.data.pageNo,
      pageSize:10
    }).then(res=>{
      console.log(this.data.pageNo)
      if(this.data.pageNo==1){
        this.setData({
          dataArr:res.data.records,
          total:res.data.total
        })
      }else{
        this.setData({
          dataArr:this.data.dataArr.concat(res.data.records),
          total:res.data.total
        })
      }
      wx.hideLoading()
    })
  },
  goDetail(e){
    let id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../../../curriculum/pages/course/index?id='+id,
    })
  },
  goBuy(e){
    let id=e.currentTarget.dataset.id;
    let curriculumType=e.currentTarget.dataset.curriculumtype;
    console.log(e.currentTarget.dataset)
    wx.navigateTo({
      url: '../../../curriculum/pages/purchase/index?id='+id+'&classification='+curriculumType,
    })
  },
  goIndex(){
    wx.switchTab({
      url: '/pages/index/index',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getData()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.total>this.data.dataArr.length){
      console.log(1)
      this.setData({
        pageNo: ++this.data.pageNo
      })
      this.getData()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})